
<script src="../js/jquery-2.1.0.min.js" type="text/javascript"></script>
<script src="../js/jquery-ui.js"></script>
<script src="../js/popup.js" type="text/javascript"></script>
<script src="../js/checker.js" type="text/javascript"></script>

<script>
	var type 	= localStorage.getItem("estudia_type");
	var course	= localStorage.getItem("estudia_course");
	
	var param 		= localStorage.getItem("estudia_currentpage");
	var num_chapter	= localStorage.getItem("estudia_maxpage");
	var chapter		= (localStorage.getItem("estudia_chapter")).charAt(0);
	
	var code	= course.substr(0,3) + "_" + "lesson" + chapter;
	
	$('#title').append("<h1>" + (localStorage.getItem("estudia_chapter")).slice(2) + "</h1>");
	
	$('#materi_next').click(function() {
		localStorage.setItem("estudia_currentpage", (parseInt(param) + 1));
		$(".middle_side").load("tampilanmateri.html", function(data) {

		});
		//alert(current);
	});
	
	$('#materi_prev').click(function() {
		localStorage.setItem("estudia_currentpage", (parseInt(param) - 1));
		$(".middle_side").load("tampilanmateri.html", function(data) {

		});
		
		//alert(current);
	});
	
	var path = "../assets/bank/materi/" + course + "/" + chapter + "-" + param + ".jpg";
	$('#lesson_image').append("<img src=\"" + path + "\"/>");
	
	if (param == 1) {
		$('#materi_next').show();
		$('#materi_prev').hide();
	}
	
	if (param == num_chapter) {
		if (num_chapter == 1) {
			$('#materi_next').hide();
			$('#materi_prev').hide();		
		} else {
			$('#materi_next').hide();
			$('#materi_prev').show();
		}
		
		if (localStorage.getItem("estudia_lesson_flag") == "true") {
			
			localStorage.removeItem("estudia_lesson_flag");
			
			var tambahan_point	= parseInt(num_chapter) * 10;
			
			if (localStorage.getItem("estudia_additionalpoint") == null) {
			
			} else {
				tambahan_point += parseInt(localStorage.getItem("estudia_additionalpoint"));
			}
			
			var current_level	= localStorage.getItem("estudia_level");
			var current_exp		= localStorage.getItem("estudia_exp");
			
			var next_level		= parseInt(current_level);
			var next_exp 		= parseInt(current_exp) + tambahan_point;
			
			var username		= localStorage.getItem("estudia_user");
			
			if ( next_exp >= 100) {
				next_level 	+= 1;
				next_exp	-= 100;
				
				if (next_level == 2) {
					createPopUp("b07", "notificator");
				} else {
					createPopUp("lvl" + next_level, "notificator");
				}
				
				if ( next_exp >= 100) {
					next_level 	+= 1;
					next_exp	-= 100;
				}
				
				localStorage.setItem("estudia_level", next_level);
				localStorage.setItem("estudia_exp", next_exp);

			} else {
				localStorage.setItem("estudia_exp", next_exp);

			}
			
			if (localStorage.getItem("estudia_achievment_b02") == "0") {
				createPopUp("b02", "notificator");
			}			
			
			if (localStorage.getItem("estudia_" + code) == 0) {
				localStorage.setItem("estudia_" + code, 1);
				
				$.get("http://estudiahapid.ap01.aws.af.cm/services/changeprogress.php?username=" + username + "&query=" + code, function(data) {
					var result = JSON.parse(data);
					
					if (result["status"] == "success") {
						//alert("success");
					} else {
						//alert("failed");
					}
				}).done(function (data) {

				}); // */
				
				if (localStorage.getItem("estudia_achievment_b05") == "0") {
					checkALesson(course.substr(0,3), function(data) {
						if (data == true) {
							createPopUp("b05", "notificator");
						}
					});
				}
				
				if (localStorage.getItem("estudia_achievment_b08") == "0") {
					checkAllLesson(function(data) {
						if (data == true) {
							createPopUp("b08", "notificator");
						}
					});
				}
			}
			
			
			$.get("http://estudiahapid.ap01.aws.af.cm/services/addpoint.php?username=" + username + "&lvl=" + next_level + "&exp=" + next_exp + "", function(data) {
				var result = JSON.parse(data);
				
				if (result["status"] == "success") {
					//alert("success");
				} else {
					//alert("failed");
				}
			}).done(function (data) {

			}); //*/
			
			$('#user_rank_level').empty();
			$('#user_rank_progressbar_detail').empty();
			$( "#user_rank_progressbar" ).empty();
			
			$('#user_rank_level').append("<h1>Level " + localStorage.getItem("estudia_level") + "</h1>");
			$('#user_rank_progressbar_detail').append("<h6>" + localStorage.getItem("estudia_exp") + " / " + "100" + "</h6>");
			$( "#user_rank_progressbar" ).progressbar({
			  value: parseInt(next_exp)
			});
		}
	} 
	
	if ((param != 1) && (param != num_chapter)) {
		$('#materi_next').show();
		$('#materi_prev').show();
	}
</script>

<div id="title"></div>
<div id="lesson_image">
	
</div>

<div class="button_materi" id="button_materi">
	<button type="button" id="materi_next">Next >></button>
	<button type="button" id="materi_prev"><< Prev</button>
</div>
